package com.simple.base.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.simple.util.common.Constants;
import com.simple.util.object.datax.DataxUserBean;

public class DataxLoginCheckInterceptor extends HandlerInterceptorAdapter{
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
			Object handler) throws Exception {
		boolean interceptor = true;
		
		String goUrl = "";
		
		final String path = request.getServletPath();
		if(!("/".equals(path)||"/index".equals(path)||"/login".equals(path)||"/logout".equals(path)||"/indextop".equals(path)||"/alertMessage".equals(path))){
			final DataxUserBean dataxUserBean= (DataxUserBean) request.getSession().getAttribute(Constants.CURRENT_SESSION_USERBEAN);
			if(dataxUserBean==null){
				goUrl = "alertMessage?errorId=message.login.userbean.null&goPage=index";
				interceptor = false;
			}
		}
		
		if(!"".equals(goUrl)){
			response.sendRedirect(goUrl);
		}
		
		return interceptor;
	}
}
